
#ifndef XDNS_HANDLER_H
#define XDNS_HANDLER_H

#include "xdns.h"
#include <string>
#include <vector>

class XdnsServerManager;
class XdnsServerState;

class XdnsHandlerImpl : public XdnsHandler
{
public:
    /*! XdnsHandlerImpl constructor.

        @param serverManager Manager of the DNS servers. This function
                             takes the ownership of this pointer.
    */
    XdnsHandlerImpl(XdnsServerManager* serverManager);
    virtual ~XdnsHandlerImpl();

    /* See xdns.h for description. */
    virtual XdnsError GetHostByName(const std::string& name,
                                    XdnsListener* listener,
                                    long* queryId);
    virtual XdnsError GetHostByAddress(const struct in_addr* ipAddress,
                                       XdnsListener* listener,
                                       long* queryId);
    virtual void CancelQuery(long queryId);
    virtual XdnsError GetProcessingFds(int* nfds,
                                       fd_set* readfds,
                                       fd_set* writefds);
    virtual XdnsError Process(fd_set* readfds,
                              fd_set* writefds);

    /*! Initialize the server states.

        @param customServers Vector of the custom DNS servers.
        @param serverStates On return the initialized server states.
        @return XE_Ok if success.
    */
    static XdnsError InitServerStates(const std::vector<XdnsServerConfig>& customServers,
                                      std::vector<XdnsServerState*>& serverStates);

private:
    // Copy constructor and assignment operator are not supported.
    XdnsHandlerImpl(const XdnsHandlerImpl& anotherHandler);
    XdnsHandlerImpl& operator=(const XdnsHandlerImpl& anotherHandler);

    XdnsServerManager* m_serverManager;
};

#endif  // XDNS_HANDLER_H

